<?php
namespace app\index\controller;
use think\Db;
use think\Controller;
use think\Config;
header('Access-Control-Allow-Origin:*');
class Index extends Controller{
    // 首页
    public function index(){
        // banner
        $bannerList = DB::name('banner')->select();
        // 主营业务
        $businessList = Db::name('business')->field('id,logo,title,content')->limit(0,4)->select();
        // 案例
        $demoList = Db::name('demo')->field('id,classic_logo,title,introduce')->limit(0,3)->select();
        // 公司动态
        $dynamicList = Db::name('dynamic')->field('id,title,introduce,logo,createtime')->order('is_top')->limit(0,3)->select();
        // 合作伙伴
        $partnerList = Db::name('partners')->select();
        // 关于我们
        $aboutUsList = Db::name('aboutus')->where('type = 1')->limit(0,2)->select();
        echo json_encode(['code' => 0,'msg' => '获取成功','bannerList'=>$bannerList,'businessList' => $businessList,'demoList' => $demoList,'dynamicList' => $dynamicList,'partnerList' => $partnerList,'aboutUsList' => $aboutUsList]);
    }
    // 站点信息
    public function getSystemInfo(){
    	$info = file_get_contents(ROOT_PATH.'public/system.txt');
    	$info = json_decode($info,true);
    	echo json_encode(['code' => 0,'msg' => '获取成功','data' => $info]);
    }
    // 发布需求
    public function sendRequest(){
        $name = trim(input('post.name'));
        $email = trim(input('post.email'));
        $number = trim(input('post.number'));
        $content = trim(input('post.content'));
        if(empty($name) || empty($email) || empty($number) || empty($content)){
            echo json_encode(['code' => 0,'msg' => '缺少参数']);
            exit;
        }
        $data['name'] = trim($name);
        $data['email'] = trim($email);
        $data['number'] = trim($number);
        $data['content'] = trim($content);
        $data['createtime'] = time();
        $result = Db::name('request')->insert($data);
        if($result){
            echo json_encode(['code' => 0,'msg' => '发布成功']);
        }else{
            echo json_encode(['code' => 1,'msg' => '发布失败']);
        }
    }
    // 驾校项目开关
    public function jiaxiaoIsClose(){
        $num = Db::name('jiaxiao')->where('id = 1')->value('sys');
        if($num == 0){
            return 'true';
        }else{
            return 'false';
        }
    }
}
